package gqz.mvvm.view.SideSlipItem;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import gqz.mvvm.R;
import gqz.mvvm.view.BaseActivity;

/**
 * Created by Administrator on 2018/1/15.
 * 左右侧滑Item
 */

public class SideSlipItemActivity extends BaseActivity {

    private ListView lv;
    private ListViewAdapter adapter;

    private ArrayList<MyBean> data = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sideslipitem);
        initView();
    }

    private void initView() {
//        lv = (ListView) findViewById(R.id.sideslip_lv);
        initData();
        adapter = new ListViewAdapter(this, data);
//        lv.setAdapter(adapter);
    }

    private void initData() {
        MyBean bean;
        for (int i = 0; i < 20; i++) {
            bean = new MyBean("Content" + (i + 1), "Left" + (i + 1), "Right" + (i + 1));
            data.add(bean);
        }
    }
}

//Adapter
class ListViewAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<MyBean> list = new ArrayList();

    public ListViewAdapter(Context context, ArrayList<MyBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_sideslip, null);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        MyBean bean = list.get(position);
        if (bean != null) {
            holder.tv_content.setText(bean.content);
            holder.tv_left.setText(bean.left);
            holder.tv_right.setText(bean.right);
        }

        return convertView;
    }

    private class ViewHolder {
        DrawerLayout dl;
        TextView tv_content, tv_left, tv_right;
    }
}
//Adapter

//bean
class MyBean {
    String content, left, right;

    public MyBean() {

    }

    public MyBean(String content, String left, String right) {
        this.content = content;
        this.left = left;
        this.right = right;
    }
}
//bean
